package Stragos.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Stragos.excepcion.DAOExcepcion;
import Stragos.modelo.Producto;
import Stragos.negocio.GestionProductos;

/**
 * Servlet implementation class ElimProd
 */
@WebServlet("/ElimProd")
public class ElimProd extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ElimProd() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try{
			GestionProductos prod = new GestionProductos();
			
			int elim  = Integer.parseInt(request.getParameter("eliminar"));
			System.out.print(elim);
			boolean x  = prod.eliminar(elim);
			if(x == true){
				request.setAttribute("eliminar", "Se elimino el producto correctamente");
				RequestDispatcher rd = request.getRequestDispatcher("MatProd.jsp");
				rd.forward(request, response);
			}else{
				request.setAttribute("eliminar", "No se pudo eliminar el producto :: Verifique sus datos");
				RequestDispatcher rd = request.getRequestDispatcher("MatProd.jsp");
				rd.forward(request, response);
			}		
			} catch (DAOExcepcion e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	
	}
}
